<template>
	<view>
		<view class="cell-list">
			<view class="cell-item">
				<view class="cell-name">{{$t('operate.brandName')}}</view> <!--品牌名称-->
				<view>{{brandData.enName}}</view>
			</view>
			<view class="cell-item">
				<view class="cell-name">{{$t('operate.categoryIcon')}}</view><!--分类图标-->
				<view>
					<image class="cell-logo" :src="brandData.logo"></image>
				</view>
			</view>
			<view class="cell-item">
				<view class="cell-name">{{$t('operate.homeTab')}}</view><!--首页tab-->
				<view>
					<u-switch v-model="isAdvice" size="40"></u-switch>
				</view>
			</view>
			<view class="cell-item">
				<view class="cell-name">{{$t('operate.menRecommendation')}}</view><!--男士推荐-->
				<view>
					<u-switch v-model="man" size="40"></u-switch>
				</view>
			</view>
			<view class="cell-item">
				<view class="cell-name">{{$t('operate.ladiesRecommend')}}</view><!--女士推荐-->
				<view>
					<u-switch v-model="women" size="40"></u-switch>
				</view>
			</view>
			<view class="cell-item">
				<view class="cell-name">{{$t('operate.recommendedForChildren')}}</view><!--儿童推荐-->
				<view>
					<u-switch v-model="child" size="40"></u-switch>
				</view>
			</view>
		</view>
		<view class="bottomBox" :style="{paddingBottom: `${bottomLift}px`}">
			<view class="button">
				<view class="add-button" @click="addClick">{{$t('publicLang.save')}}</view><!--保存-->
			</view>
		</view>
	</view>
</template>

<script>
	let app = getApp();
	import {
		brandRecommendUpdate,
		brandAdvice
	} from '@/api/brand.js';
	export default {
		data() {
			return {
				brandData: {},
				isAdvice: 0,
				man: 0,
				women: 0,
				child: 0,
				bottomLift: app.globalData.bottomLift,
			}
		},
		onLoad() {
			let _this = this
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('brandDetailsData', function(data) {
				console.log(data.data)
				if (data.data.cateHotList.length > 0) {
					data.data.cateHotList.map((i, index) => {
						if (i == 1) {
							_this.man = 1
						}
						if (i == 2) {
							_this.women = 1
						}
						if (i == 3) {
							_this.child = 1
						}
					})
				}
				_this.brandData = data.data
				_this.isAdvice = data.data.isAdvice
			})
		},
		onShow() {
			uni.setNavigationBarTitle({
				title: this.$t('navigation.brandDetails')
			});
		},
		methods: {
			addClick() {
				let data = {
					brandId: this.brandData.id,
					typeList: []
				}
				let dataAdvice = {
					id: this.brandData.id,
					isAdvice: this.isAdvice?1:0,
					type: 1
				}
				if (this.man == 1) {
					data.typeList.push("1")
				}
				if (this.women == 1) {
					data.typeList.push("2")
				}
				if (this.child == 1) {
					data.typeList.push("3")
				}
				let _this = this

				// var p = new Promise(function(resolve, reject) {
				// 	brandRecommendUpdate(data).then(res => {
				// 		resolve()
				// 	})
				// });
				// var p1 = new Promise(function(resolve, reject) {
				// 	brandAdvice(dataAdvice).then(res => {
				// 		resolve()
				// 	})
				// });
				// Promise.all([p, p1]).then(function(values) {
				// 	_this.$util.Tips({
				// 		title: '编辑成功'
				// 	});
				// 	setTimeout(function() {
				// 		const eventChannel = _this.getOpenerEventChannel();
				// 		eventChannel.emit('someEvent', {data: ''});
				// 		uni.navigateBack()
				// 	}, 1500);
				// });
				brandRecommendUpdate(data).then(res => {
					brandAdvice(dataAdvice).then(res => {
						_this.$util.Tips({
							title: _this.$t('operate.editedSuccessfully')
						});
						setTimeout(function() {
							const eventChannel = _this.getOpenerEventChannel();
							eventChannel.emit('someEvent', {data: ''});
							uni.navigateBack()
						}, 1500);
					})
				})
				
			}
		}
	}
</script>

<style lang="scss">
	.cell-list {
		.cell-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 34rpx 40rpx;
			background-color: #FFFFFF;
			border-bottom: 1rpx solid #F5F5F8;

			.cell-name {
				color: #666666;
			}

			.cell-logo {
				width: 80rpx;
				height: 80rpx;
				border: 1rpx solid #F1F1F1;
			}
		}
	}

	.bottomBox {
		background-color: #FFFFFF;
		width: 100%;
		position: fixed;
		bottom: 0;
	}

	.button {
		width: 100%;
		height: 128rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.add-button {
		width: 690rpx;
		height: 92rpx;
		background-color: #111111;
		color: #FFFFFF;
		font-size: 32rpx;
		text-align: center;
		line-height: 92rpx;
	}
</style>
